package cn.wolfcode.web.controller;


import cn.wolfcode.domain.MessageBoardZal;
import cn.wolfcode.domain.SystemDictionaryItem;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IMessageBoardZalService;
import cn.wolfcode.service.ISystemDictionaryItemService;
import cn.wolfcode.util.RequestPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/messageBoardZal")
public class MessageBoardZalController {

    @Autowired
    private IMessageBoardZalService messageBoardZalService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;


    @RequestPermission(name="留言板页面",expression="messageBoardZal:list")
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<MessageBoardZal> pageInfo = messageBoardZalService.query(qo);
        List<SystemDictionaryItem> systemDictionaryItems = systemDictionaryItemService.selectByType(1);
        model.addAttribute("systemDictionaryItems",systemDictionaryItems);
        model.addAttribute("pageInfo", pageInfo);
        return "messageBoardZal/list";
    }


    @RequestPermission(name="留言板新增",expression="messageBoardZal:save")
    @RequestMapping("/save")
    public String saveOrUpdate(MessageBoardZal messageBoardZal) {
        messageBoardZalService.save(messageBoardZal);
        return "redirect:/messageBoardZal/list";
    }

}
